/*     */ package com.zimbra.cs.account.accesscontrol;
/*     */ 
/*     */ import com.google.common.collect.Maps;
/*     */ import com.google.common.collect.Sets;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.StringUtil;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Entry;
/*     */ import com.zimbra.cs.account.Group;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.ldap.entry.LdapEntry;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class DiscoverUserRights
/*     */ {
/*     */   private final Account acct;
/*     */   private final Set<Right> rights;
/*     */   private final boolean onMaster;
/*     */   
/*     */   DiscoverUserRights(Account credentials, Set<Right> rights, boolean onMaster)
/*     */     throws ServiceException
/*     */   {
/*  42 */     if (rights.size() == 0) {
/*  43 */       throw ServiceException.FAILURE("no right is specified", null);
/*     */     }
/*  45 */     this.acct = credentials;
/*  46 */     this.rights = Sets.newHashSet(rights);
/*  47 */     this.onMaster = onMaster;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   Map<Right, Set<Entry>> handle()
/*     */     throws ServiceException
/*     */   {
/*  59 */     Provisioning prov = Provisioning.getInstance();
/*     */     
/*     */ 
/*  62 */     Set<TargetType> targetTypesToSearch = Sets.newHashSet();
/*  63 */     for (Right right : this.rights) {
/*  64 */       TargetType targetType = right.getTargetType();
/*  65 */       targetTypesToSearch.add(targetType);
/*     */       
/*     */ 
/*  68 */       if (targetType == TargetType.dl) {
/*  69 */         targetTypesToSearch.add(TargetType.group);
/*  70 */       } else if (targetType == TargetType.group) {
/*  71 */         targetTypesToSearch.add(TargetType.dl);
/*     */       }
/*     */     }
/*     */     
/*  75 */     SearchGrants search = new SearchGrants(prov, targetTypesToSearch, this.acct, this.rights, this.onMaster);
/*  76 */     Set<SearchGrants.GrantsOnTarget> searchResults = search.doSearch().getResults();
/*     */     
/*  78 */     Map<Right, Set<Entry>> result = Maps.newHashMap();
/*     */     
/*  80 */     for (SearchGrants.GrantsOnTarget grants : searchResults) {
/*  81 */       targetEntry = grants.getTargetEntry();
/*  82 */       ZimbraACL acl = grants.getAcl();
/*     */       
/*  84 */       for (ZimbraACE ace : acl.getAllACEs()) {
/*  85 */         Right right = ace.getRight();
/*     */         
/*  87 */         if ((this.rights.contains(right)) && (!isSameEntry(targetEntry, this.acct)))
/*     */         {
/*  89 */           if (((!(targetEntry instanceof Account)) && (!(targetEntry instanceof Group))) || (ace.getGranteeType() != GranteeType.GT_USER) || 
/*     */           
/*  91 */             (StringUtil.equal(this.acct.getId(), ace.getGrantee())))
/*     */           {
/*     */ 
/*     */ 
/*     */ 
/*  96 */             TargetType targetTypeForRight = right.getTargetType();
/*  97 */             TargetType taregtTypeOfEntry = TargetType.getTargetType(targetEntry);
/*  98 */             if ((targetTypeForRight.equals(taregtTypeOfEntry)) || ((targetTypeForRight == TargetType.account) && (taregtTypeOfEntry == TargetType.calresource)) || ((targetTypeForRight == TargetType.dl) && (taregtTypeOfEntry == TargetType.group)) || ((targetTypeForRight == TargetType.group) && (taregtTypeOfEntry == TargetType.dl)))
/*     */             {
/*     */ 
/*     */ 
/* 102 */               Set<Entry> entries = (Set)result.get(right);
/* 103 */               if (entries == null) {
/* 104 */                 entries = Sets.newHashSet();
/* 105 */                 result.put(right, entries);
/*     */               }
/* 107 */               entries.add(targetEntry);
/*     */             }
/*     */           } }
/*     */       } }
/*     */     Entry targetEntry;
/* 112 */     return result;
/*     */   }
/*     */   
/*     */   private boolean isSameEntry(Entry entry1, Entry entry2) throws ServiceException {
/* 116 */     if (((entry1 instanceof LdapEntry)) && ((entry2 instanceof LdapEntry))) {
/* 117 */       String entry1DN = ((LdapEntry)entry1).getDN();
/* 118 */       String entry2DN = ((LdapEntry)entry2).getDN();
/* 119 */       return (entry1DN != null) && (entry2DN != null) && (entry1DN.equals(entry2DN));
/*     */     }
/* 121 */     throw ServiceException.FAILURE("internal server error - not LdapEntry", null);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/accesscontrol/DiscoverUserRights.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */